import java.util.Iterator;
import java.util.Scanner;


public class Main {

	static Menu eatAtDrewsMenu = new Menu();
	static MenuItem item = null;
	static Iterator itr;
	private static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		
		String choice = "y";
		while (choice.equals("y")) {
			programLoop();
			System.out.println();
			System.out.println("Would you like to continue? ('y','n')");
			sc.nextLine();
			choice = sc.nextLine();
		}
	}
	
	public static void programLoop() {
		int choice=0;
		while (choice < 1 || choice > 8) {
			System.out.println("1. Display all menu items");
			System.out.println("2. Display all appetizers");
			System.out.println("3. Display all main dishes");
			System.out.println("4. Display all desserts");
			System.out.println("5. Display all heart healthy items");
			System.out.println("6. Display all main dishes under a specified price");
			System.out.println("7. Add menu item");
			System.out.println("8. Remove menu item");
			choice = sc.nextInt();
		}
	
		switch (choice) {
			case 1:  
				itr = eatAtDrewsMenu.getMenuIterator();
				System.out.println("ALL MENU ITEMS");
				while (itr.hasNext()) { 
					item = (MenuItem) itr.next(); 
					System.out.println(item.itemName() + " $" + item.price());
				}
				break;
	        case 2:
	        	itr = eatAtDrewsMenu.getMenuItemIterator();
	        	System.out.println("APPETIZERS");
	        	while (itr.hasNext()) { 
					item = (MenuItem) itr.next();
					if (item.category() == 1)
						System.out.println(item.itemName() + " $" + item.price());
				}
	        	break;
	        case 3:
	        	itr = eatAtDrewsMenu.getMenuItemIterator();
	        	System.out.println("MAIN DISHES");
	        	while (itr.hasNext()) { 
					item = (MenuItem) itr.next(); 
					if (item.category() == 2)
						System.out.println(item.itemName() + " $" + item.price());
				}
	        	break;
	        case 4:
	        	itr = eatAtDrewsMenu.getMenuItemIterator();
	        	System.out.println("DESSERTS");
	        	while (itr.hasNext()) { 
					item = (MenuItem) itr.next(); 
					if (item.category() == 3)
						System.out.println(item.itemName() + " $" + item.price());
				}
	        	break;
	        case 5:
	        	itr = eatAtDrewsMenu.getHeartHealthyIterator();
	        	System.out.println("HEART HEALTHY ITEMS");
	        	while (itr.hasNext()) { 
					item = (MenuItem) itr.next(); 
					if (item.isHealthy() == true)
						System.out.println(item.itemName() + " $" + item.price());
				}
	        	break;
	        case 6:
	        	System.out.println("Enter specified price:");
	        	double amount = sc.nextDouble();
	        	itr = eatAtDrewsMenu.getPriceIterator();
	        	System.out.println("ITEMS UNDER $" + amount);
	        	while (itr.hasNext()) { 
					item = (MenuItem) itr.next(); 
					if (item.price() < amount) {
						System.out.println(item.itemName() + " $" + item.price());
					}
				}
	        	break;
	        case 7:  
	        	add();
	        	break;
	        case 8:  
	        	delete();
                break;
	        default: 
	        	break;
	        }
	}
	
	public static void add () {
		String answer1; int answer2; String tempAnswer = ""; boolean answer3; double answer4;
		
		sc.nextLine();
		System.out.println("Please enter the dish name:");
		answer1 = sc.nextLine();
		System.out.println("Please enter dish category:");
		System.out.println("Type 1 for appetizers");
		System.out.println("Type 2 for main dishes");
		System.out.println("Type 3 for desserts");
		answer2 = sc.nextInt();
		sc.nextLine();
		System.out.println("Is this dish heart healthy? ('y', 'n')");
		tempAnswer = sc.nextLine();
		System.out.println("How much does this dish cost?");
		answer4 = sc.nextDouble();
	
		if (tempAnswer.equals("y"))
			answer3 = true;
		else
			answer3 = false;
		
		MenuItem newItem = (new MenuItem(answer1,answer2,answer3,answer4));
		Menu.add(newItem);
	}
	
	public static void delete () {
		System.out.println("Enter the number listed next to the item you would like to delete:");
		
		itr = eatAtDrewsMenu.getMenuIterator();
		int count = 1;
		while (itr.hasNext()) { 
			item = (MenuItem) itr.next(); 
			System.out.println(count + ". " + item.itemName() + " $" + item.price());
			count++;
		}
		
		int i = sc.nextInt();
		Menu.delete(i-1);
	}
}
